<?php
declare (strict_types = 1); // oi小鬼，启用严格模式先

namespace app\command\im;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use app\logic\im\SnsLogic;

class Sns extends Command
{
    // 此命令用于执行SNS相关的命令
    protected function configure()
    {
        $this->setName('ImSnsCommand')
            ->addArgument('function', Argument::OPTIONAL, "function", "syncFriendList")
        	->addOption('from_account', '', Option::VALUE_OPTIONAL, "IM的用户ID")
        	->setDescription('IM SNS Command');
    }

    protected function execute(Input $input, Output $output)
    {
        $function = trim($input->getArgument('function'));
      	$function = $function ?: 'syncFriendList';

        $data = [
            'from_account' => ''
        ];
        if($input->hasOption('from_account')){
            $data['from_account'] = $input->getOption('from_account');
        }

        $output->writeln(
            "开始执行IM SNS {$function}: 
                " . json_encode($data)
        );

        (new SnsLogic)->{$function}($data);
    }
}
